import Vue from 'vue'

import moment from 'moment-timezone'
import 'moment/locale/zh-cn'
moment.locale('zh-cn')
moment.tz.setDefault("Asia/Shanghai");
Vue.prototype.$moment = moment;//赋值使用
Vue.filter('NumberFormat', function (num) {
  num = parseFloat(Number(num).toFixed(3))
  let [integer, decimal] = String.prototype.split.call(num, '.')
  integer = integer.replace(/\d(?=(\d{3})+$)/g, '$&,') // 正则先行断言
  return `${integer}${decimal ? '.' + decimal : ''}`
})

Vue.filter('dayjs', function (dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
  return moment(dataStr).format(pattern)
})

Vue.filter('moment', function (dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
  return moment(dataStr).format(pattern)
})
